package com.zay.a5_buttons;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import androidx.annotation.Nullable;

public class MySQLiteOpenHelper extends SQLiteOpenHelper {
    //数据库初始版本号
    private static final int DATABASE_VERSION = 1;
    public MySQLiteOpenHelper(@Nullable Context context, @Nullable String name, @Nullable SQLiteDatabase.CursorFactory factory, int version) {
        super(context, name, factory, version);
    }
    @Override
    public void onCreate(SQLiteDatabase sqLiteDatabase) {
        sqLiteDatabase.execSQL("create table book_info(" +
                "book_id integer primary key autoincrement," +
                "book_name varchar," +
                "book_publish varchar," +
                "book_price double)");
        sqLiteDatabase.execSQL("create table user_tab(" +
                "uid integer primary key autoincrement," +
                "uAccount varchar(50)," +
                "uPassword varchar(50))");
    }
    @Override
    public SQLiteDatabase getWritableDatabase() {
        return super.getWritableDatabase();
    }
    @Override
    public SQLiteDatabase getReadableDatabase() {
        return super.getReadableDatabase();
    }
    @Override
    public void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i1) {
        sqLiteDatabase.execSQL("drop table if exists book_info");
        sqLiteDatabase.execSQL("drop table if exists user_tab");
        onCreate(sqLiteDatabase);
    }
}
